#!/usr/bin/python

from lib import robot_lib
from lib import shell


class RobotCommands(shell.BaseCommand):

  def cmdShow(self, *args):

    if len(args) == 0:
      self.shell.Error('show what?')

    command = args[0].lower()
    if command == 'power':
      self.__ShowBattery()
    elif command == 'battery':
      self.__ShowBattery()
    elif command == 'bob':
      self.shell.Info('bob!')
    else:
      self.shell.Error('show: invalid command: %s' % command)

  def __ShowBattery(self):
    self.shell.Print('%s mw' % self.robot.Brick().get_battery_level())


class CricketCommands(shell.BaseCommand):

  def cmdStartUp(self, *args):
    try:
      self.robot.Connect()
      self.shell.Print('Robot online')
    except robot_lib.RobotNotConnected, e:
      self.shell.Error('No connection to robot: %s' % e)


class SoundCommands(shell.BaseCommand):

  def cmdChirp(self, *args):
    FREQ_C = 350
    FREQ_D = 550
    DELAY = 500

    for x in range(1):
      self.robot.Brick().play_tone_and_wait(FREQ_C, DELAY)
      self.robot.Brick().play_tone_and_wait(FREQ_D, DELAY)
